<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;

?>

<div class="income-form">

    <?php $form = ActiveForm::begin([
             'id' => 'income_id',
             'options' => ['enctype' => 'multipart/form-data',],
             'layout' => 'horizontal',
             'enableAjaxValidation'=>true,
             'fieldConfig' => [
                'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
                'horizontalCssClasses' => [
                    'label' => 'col-sm-2',
                    'wrapper' => 'col-sm-7',
                    'error' => '',
                ],
             ],
        ]); ?>

    <?= $form->field($model, 'company')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'currency')->inline(true)->radioList(Yii::$app->params['currency_type']) ?>

    <?= $form->field($model, 'price')->textInput(['maxlength' => true,'readonly'=>'readonly']) ?>

    <?= $form->field($model, 'real_price')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'pro_price')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'remark')->textArea(['maxlength' => true]) ?>

    <div class="form-group text-center">
        <?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-success']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">  

    $("#income_id").on("change","#income-real_price,#income-pro_price",function(){
        var price = 0;
        var real_price = $("#income-real_price").val();
        var pro_price = $("#income-pro_price").val();
        real_price == '' ? real_price = 0 : '';
        pro_price == '' ? pro_price = 0 : '';
        price = parseFloat(real_price) + parseFloat(pro_price);
        price=price.toFixed(2);
        $("#income-price").val(price);
    });
    
</script>
<?php app\components\JsBlock::end() ?>
